libname everify "D:\state immigration laws\RESTATREVISION\program files for RESTAT readme";
options nocenter;
options linesize=78;
data everify.combined (compress=yes);
set everify.combined0309 everify.combined9802;
run;


data everify.t1;
set everify.combined;
if year>2002 and prdtind1 in (1,2,3) then ind1=1;
else if year<2003 and prdtind1 in (1,2,3,47) then ind1=1;
else ind1=0;

if year>2002 and prdtind1 in (4) then ind2=1;
else if year<2003 and prdtind1 in (4) then ind2=1;
else ind2=0;

if year>2002 and prdtind1 in (5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) then ind3=1;
else if year <2003 and prdtind1 in (5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28) then ind3=1;
else ind3=0;

if year>2002 and prdtind1 in (21) then ind4=1;
else if year<2003 and prdtind1 in (32) then ind4=1;
else ind4=0;


if year>2002 and prdtind1 in (22) then ind5=1;
else if year<2003 and prdtind1 in (33,34) then ind5=1;
else ind5=0;


if year>2002 and prdtind1 in (23,24,25,26,27,28,29,30,31) then ind6=1;
else if year<2003 and prdtind1 in (29,30,31) then ind6=1;
else ind6=0;

if year>2002 and prdtind1 in (32,33,34,35) then ind8=1;
else if year<2003 and prdtind1 in (35,36) then ind8=1;
else ind8=0;

if year>2002 and prdtind1 in (36,37,38,39,40,41,42,43,44,45,46,47,48,49,50) then ind9=1;
else if year<2003 and prdtind1 in (37,38,39,40,41,42,43,44,45,46) then ind9=1;
else ind9=0;

if year>2002 and prdtind1 in (51) then ind10=1;
else if year<2003 and prdtind1 in (48,49,50,51) then ind10=1;
else ind10=0;

if year>2002 and prdtind1 in (52) then ind11=1;
else if year<2003 and prdtind1 in (52) then ind11=1;
else ind11=0;

if race=1 and hispanic=2 then racer=1;
else if race=2 and hispanic=2 then racer=2;
else if race=3 and hispanic=2 then racer=3;
else if race=4 and hispanic=2 then racer=4;
else if racer>4 and hispanic=2 then racer=5;
else if hispanic=1 then racer=6;
if sex=2 then female=1; else female=0;

if 31 le educ le 38 then educrecode=1;
else if educ=39 then educrecode=2;
else if 40 le educ le 42 then educrecode=3;
else if educ ge 43 then educrecode=4;
else educrecode=".";
if educrecode=1 then educ1=1; else educ1=0;
if educrecode=2 then educ2=1; else educ2=0;
if educrecode=3 then educ3=1; else educ3=0;
if educrecode=4 then educ4=1; else educ4=0;
if country ge 100 and citizen in (4,5) then foreign=1; else foreign=0;
if hispanic=1 then hispdummy=1; else hispdummy=0;
foreignhispanic=foreign*hispdummy;
foreigneduc1=foreign*educ1;
foreigneduc2=foreign*educ2;
foreigneduc3=foreign*educ3;
foreigneduc4=foreign*educ4;

if citizen=5 then noncitizen=1; else noncitizen=0;
hispnoncitizen=noncitizen*hispdummy;
hispnoncitizene1=noncitizen*hispdummy*educ1;
hispnoncitizene2=noncitizen*hispdummy*educ2;

if noncitizen=0 and hispdummy=1 and foreign=1 then hispcitizen=1; else hispcitizen=0;

if citizen in (1,2,3) then citizenship=1;
else if citizen=4 then citizenship=2;
else if citizen=5 then citizenship=3;
if employment in (1,2) then employed=1; else employed=0;
statefip=gestfips;
run;


proc sort;
by statefip year;
run;


proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where 15 le age;
output out=everify.ageo15 mean=foreigno15 hispdummyo15 foreignhispanico15 
noncitizeno15 hispnoncitizeno15 hispnoncitizene1o15 hispnoncitizene2o15 hispcitizeno15;
run;






proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
output out=everify.poppanel mean=;
run;
proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where employed=1;
output out=everify.poppanel4 mean=foreignw hispdummyw 
foreignhispanicw noncitizenw hispnoncitizenw hispnoncitizene1w hispnoncitizene2w hispcitizenw;
run;


proc means noprint data=everify.t1;
var educ1 educ2 educ3 educ4;
by statefip year;
weight weight;
where age>17;
output out=poppanel2 mean=;
run;
proc means noprint data=everify.t1;
var educ1 educ2 educ3 educ4;
by statefip year;
weight weight;
where employed=1;
output out=poppanel3 mean=educ1w educ2w educ3w educ4w;
run;


proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where age<15;
output out=everify.age1 mean=foreignch hispdummych foreignhispanicch
noncitizench hispnoncitizench hispnoncitizene1ch hispnoncitizene2ch hispcitizench;
run;
proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where 15 le age le 45;
output out=everify.age2 mean=foreign1545 hispdummy1545 foreignhispanic1545 
noncitizen1545 hispnoncitizen1545 hispnoncitizene11545 hispnoncitizene21545 hispcitizen1545;
run;
proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where 45<age;
output out=everify.age3 mean=foreign46 hispdummy46 foreignhispanic46 noncitizen46 
hispnoncitizen46 hispnoncitizene146 hispnoncitizene246 hispcitizen46;
run;

proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where 15 le age le 45 and female=0;
output out=everify.age4 mean=foreign1545m hispdummy1545m foreignhispanic1545m 
noncitizen1545m hispnoncitizen1545m hispnoncitizene11545m hispnoncitizene21545m hispcitizen1545m;
run;

proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2 hispcitizen;
by statefip year;
weight weight;
where 15 le age le 45 and female=1;
output out=everify.age5 mean=foreign1545f hispdummy1545f foreignhispanic1545f 
noncitizen1545f hispnoncitizen1545f hispnoncitizene11545f hispnoncitizene21545f hispcitizen1545f;
run;
























proc means noprint data=everify.t1;
var foreign hispdummy foreignhispanic noncitizen hispnoncitizen hispnoncitizene1 hispnoncitizene2;
by statefip year;
output out=test2 sum=foreigns hispdummys foreignhispanics noncitizens
hispnoncitizens hispnoncitizene1s hispnoncitizene2s;
weight weight;
run;
proc means noprint data=everify.t1;
var educ1 educ2 educ3 educ4;
by statefip year;
weight weight;
where age>17;
output out=test3 sum=educ1s educ2s educ3s educ4s;
run;
proc means noprint data=everify.t1;
var educ1 educ2 educ3 educ4;
by statefip year;
weight weight;
where employed=1;
output out=test4 sum=educ1ws educ2ws educ3ws educ4ws;
run;





data test2;
set test2;
foreigns=foreigns/12;
hispdummys=hispdummys/12; 
foreignhispanics=foreignhispanics/12; 
noncitizens=noncitizens/12;
hispnoncitizens=hispnoncitizens/12;
run;
data test3;
set test3;
educ1s=educ1s/12;
educ2s=educ2s/12;
educ3s=educ3s/12;
educ4s=educ4s/12;
run;
data test4;
set test4;
educ1ws=educ1ws/12;
educ2ws=educ2ws/12;
educ3ws=educ3ws/12;
educ4ws=educ4ws/12;
run;



data everify.populationtotals;
merge test2 test3 test4 everify.poppanel poppanel2 poppanel3 
everify.poppanel4 everify.age1 everify.age2 everify.age3 everify.age4 everify.age5;
by statefip year;
run;

proc means noprint data=everify.t1;
var ind1 ind2 ind3 ind4 ind5 ind6 ind8 ind9 ind10 ind11;
by statefip year;
weight weight;
where employed=1;
output out=everify.ind mean=;
run;

data everify.populationtotals;
merge everify.populationtotals everify.ind;
by statefip year;
run;

proc sort data=everify.state_unemployment_rats;
by statefip year;
run;

data everify.populationtotals;
merge everify.populationtotals everify.state_unemployment_rats;
run;


data everify.populationtotals;
merge everify.populationtotals everify.ageo15;
run;
